<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>移动web开发之flex布局 | To Share</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/share/favicon.ico">
    <meta name="description" content="分享风雨，享受阳光">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/share/assets/css/0.styles.d7affcea.css" as="style"><link rel="preload" href="/share/assets/js/app.706684de.js" as="script"><link rel="preload" href="/share/assets/js/3.4685d505.js" as="script"><link rel="preload" href="/share/assets/js/1.b12738fb.js" as="script"><link rel="preload" href="/share/assets/js/25.c1c35d96.js" as="script"><link rel="preload" href="/share/assets/js/9.4e81f08e.js" as="script"><link rel="prefetch" href="/share/assets/js/10.9e95ce7b.js"><link rel="prefetch" href="/share/assets/js/11.e99410dc.js"><link rel="prefetch" href="/share/assets/js/12.e9afe07c.js"><link rel="prefetch" href="/share/assets/js/13.078dd281.js"><link rel="prefetch" href="/share/assets/js/14.6575b8f0.js"><link rel="prefetch" href="/share/assets/js/15.d942bb10.js"><link rel="prefetch" href="/share/assets/js/16.fd8cc40c.js"><link rel="prefetch" href="/share/assets/js/17.f1b1f2c6.js"><link rel="prefetch" href="/share/assets/js/18.b312ce79.js"><link rel="prefetch" href="/share/assets/js/19.a99d170f.js"><link rel="prefetch" href="/share/assets/js/20.cda2b911.js"><link rel="prefetch" href="/share/assets/js/21.d6062607.js"><link rel="prefetch" href="/share/assets/js/22.5a50eee4.js"><link rel="prefetch" href="/share/assets/js/23.be601eed.js"><link rel="prefetch" href="/share/assets/js/24.3d0b9811.js"><link rel="prefetch" href="/share/assets/js/26.9a8b03ff.js"><link rel="prefetch" href="/share/assets/js/27.6c302f3e.js"><link rel="prefetch" href="/share/assets/js/28.5eb55960.js"><link rel="prefetch" href="/share/assets/js/29.8297842b.js"><link rel="prefetch" href="/share/assets/js/30.b453256b.js"><link rel="prefetch" href="/share/assets/js/31.6ce2e46f.js"><link rel="prefetch" href="/share/assets/js/32.cf3906ab.js"><link rel="prefetch" href="/share/assets/js/33.83680f76.js"><link rel="prefetch" href="/share/assets/js/34.dada508c.js"><link rel="prefetch" href="/share/assets/js/35.11a36f17.js"><link rel="prefetch" href="/share/assets/js/36.fc43ef74.js"><link rel="prefetch" href="/share/assets/js/37.af715eba.js"><link rel="prefetch" href="/share/assets/js/38.7ba3e6e1.js"><link rel="prefetch" href="/share/assets/js/39.cd1c9d09.js"><link rel="prefetch" href="/share/assets/js/4.c1f99423.js"><link rel="prefetch" href="/share/assets/js/40.8df0c044.js"><link rel="prefetch" href="/share/assets/js/41.e643a418.js"><link rel="prefetch" href="/share/assets/js/42.d809cd4f.js"><link rel="prefetch" href="/share/assets/js/43.5136999f.js"><link rel="prefetch" href="/share/assets/js/44.315a82bf.js"><link rel="prefetch" href="/share/assets/js/45.a4b04306.js"><link rel="prefetch" href="/share/assets/js/46.2e8ec77e.js"><link rel="prefetch" href="/share/assets/js/47.d6bde2ca.js"><link rel="prefetch" href="/share/assets/js/48.e8e85c15.js"><link rel="prefetch" href="/share/assets/js/49.fce2ff19.js"><link rel="prefetch" href="/share/assets/js/5.599dfd12.js"><link rel="prefetch" href="/share/assets/js/50.3918e713.js"><link rel="prefetch" href="/share/assets/js/51.c5ddf50e.js"><link rel="prefetch" href="/share/assets/js/52.b6653f73.js"><link rel="prefetch" href="/share/assets/js/53.c0420367.js"><link rel="prefetch" href="/share/assets/js/54.0f64522f.js"><link rel="prefetch" href="/share/assets/js/55.1f9ce6fb.js"><link rel="prefetch" href="/share/assets/js/56.0a2fc30f.js"><link rel="prefetch" href="/share/assets/js/57.3b81efcb.js"><link rel="prefetch" href="/share/assets/js/58.c617dcad.js"><link rel="prefetch" href="/share/assets/js/59.5239e9d4.js"><link rel="prefetch" href="/share/assets/js/6.4e5676a9.js"><link rel="prefetch" href="/share/assets/js/60.b614d70b.js"><link rel="prefetch" href="/share/assets/js/61.f45be005.js"><link rel="prefetch" href="/share/assets/js/62.52121455.js"><link rel="prefetch" href="/share/assets/js/63.9f699597.js"><link rel="prefetch" href="/share/assets/js/64.01c4bf37.js"><link rel="prefetch" href="/share/assets/js/65.0f31fd4b.js"><link rel="prefetch" href="/share/assets/js/66.55dbbe80.js"><link rel="prefetch" href="/share/assets/js/67.fd9ba6df.js"><link rel="prefetch" href="/share/assets/js/68.c6c9e158.js"><link rel="prefetch" href="/share/assets/js/69.91757641.js"><link rel="prefetch" href="/share/assets/js/7.b8928c33.js"><link rel="prefetch" href="/share/assets/js/70.12f0a894.js"><link rel="prefetch" href="/share/assets/js/71.88c99794.js"><link rel="prefetch" href="/share/assets/js/72.e1d99c59.js"><link rel="prefetch" href="/share/assets/js/73.aee6f06a.js"><link rel="prefetch" href="/share/assets/js/74.b47532b0.js"><link rel="prefetch" href="/share/assets/js/75.1f1ab66e.js"><link rel="prefetch" href="/share/assets/js/8.56deb6eb.js">
    <link rel="stylesheet" href="/share/assets/css/0.styles.d7affcea.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-130b300a><div data-v-130b300a><div class="password-shadow password-wrapper-out" style="display:none;" data-v-25ba6db2 data-v-130b300a data-v-130b300a><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>To Share</h3> <p class="description" data-v-25ba6db2 data-v-25ba6db2>分享风雨，享受阳光</p> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><!---->
            
          <span data-v-25ba6db2>2018 - </span>
          2022
        </a></span></div></div> <div class="hide" data-v-130b300a><header class="navbar" data-v-130b300a><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/share/" class="home-link router-link-active"><!----> <span class="site-name">To Share</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/share/" class="nav-link"><i class="iconfont reco-home"></i>
  Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      Category
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/categories/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/flex/" class="nav-link"><i class="undefined"></i>
  flex
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/css/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/gui/" class="nav-link"><i class="undefined"></i>
  gui
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/linux/" class="nav-link"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/nodeJs/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/share/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div><div class="nav-item"><a href="/share/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  TimeLine
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      Docs
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/docs/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/flex/" aria-current="page" class="nav-link router-link-exact-active router-link-active"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/node/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/linux/" class="nav-link"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/gui/" class="nav-link"><i class="undefined"></i>
  GUI
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li></ul></div></div><div class="nav-item"><a href="https://gitee.com/zenglingchuan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-130b300a></div> <aside class="sidebar" data-v-130b300a><div class="personal-info-wrapper" data-v-39576ba9 data-v-130b300a><img src="/share/avatar.png" alt="author-avatar" class="personal-img" data-v-39576ba9> <!----> <div class="num" data-v-39576ba9><div data-v-39576ba9><h3 data-v-39576ba9>63</h3> <h6 data-v-39576ba9>文章</h6></div> <div data-v-39576ba9><h3 data-v-39576ba9>51</h3> <h6 data-v-39576ba9>标签</h6></div></div> <ul class="social-links" data-v-39576ba9></ul> <hr data-v-39576ba9></div> <nav class="nav-links"><div class="nav-item"><a href="/share/" class="nav-link"><i class="iconfont reco-home"></i>
  Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      Category
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/categories/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/flex/" class="nav-link"><i class="undefined"></i>
  flex
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/css/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/gui/" class="nav-link"><i class="undefined"></i>
  gui
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/linux/" class="nav-link"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/nodeJs/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/share/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div><div class="nav-item"><a href="/share/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  TimeLine
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      Docs
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/docs/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/flex/" aria-current="page" class="nav-link router-link-exact-active router-link-active"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/node/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/linux/" class="nav-link"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/gui/" class="nav-link"><i class="undefined"></i>
  GUI
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li></ul></div></div><div class="nav-item"><a href="https://gitee.com/zenglingchuan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav> <ul class="sidebar-links"><li><a href="/share/docs/flex/" aria-current="page" class="active sidebar-link">移动web开发之flex布局</a></li><li><a href="/share/docs/flex/layout.html" class="sidebar-link">网页布局</a></li><li><a href="/share/docs/flex/cssBase.html" class="sidebar-link">css常见问题</a></li><li><a href="/share/docs/flex/bootstrap.html" class="sidebar-link">响应式布局</a></li><li><a href="/share/docs/flex/skill.html" class="sidebar-link">css技巧</a></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-25ba6db2 data-v-130b300a><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>移动web开发之flex布局</h3> <!----> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><!---->
            
          <span data-v-25ba6db2>2018 - </span>
          2022
        </a></span></div></div> <div data-v-130b300a><main class="page"><section><div class="page-title"><h1 class="title">移动web开发之flex布局</h1> <div data-v-f875f3fc><!----> <i class="iconfont reco-date" data-v-f875f3fc><span data-v-f875f3fc>2022/9/2</span></i> <!----> <i class="tags iconfont reco-tag" data-v-f875f3fc><span class="tag-item" data-v-f875f3fc>flex</span></i></div></div> <div class="theme-reco-content content__default"><div id="boxx" data-v-f4ca0dac><div data-v-f4ca0dac><p v-if="true" class="custom-block-title" data-v-f4ca0dac></p> <p v-if="true" data-v-f4ca0dac></p></div></div> <h2 id="flex布局体验"><a href="#flex布局体验" class="header-anchor">#</a> flex布局体验</h2> <h3 id="传统布局与flex布局"><a href="#传统布局与flex布局" class="header-anchor">#</a> 传统布局与flex布局</h3> <ul><li>传统布局
<ul><li>兼容性好</li> <li>布局繁琐</li> <li>局限性， 不能再移动端很好的布局</li></ul></li> <li>flex布局
<ul><li>操作方便， 布局极为简单， 移动端应用很广泛</li> <li>PC端浏览器支持情况较差</li> <li>IE 11或者更低版本， 不支持或者部分支持</li></ul></li></ul> <p style="color:blue;font-weight:bolder;">建议：</p> <ul><li>如果是PC端页面布局， 我们还是采用传统布局比较好；</li> <li>如果是移动端或者不考虑兼容性问题的PC端页面布局， 我们使用flex弹性布局更佳！</li></ul> <h3 id="示例-三等分一个盒子"><a href="#示例-三等分一个盒子" class="header-anchor">#</a> 示例: 三等分一个盒子</h3> <blockquote><p>使用flex布局之后， 就不分行内元素和块级元素， 都是有大小的， 这里就可以用span了</p></blockquote> <img src="/share/flex/01.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">div</span><span class="token punctuation">{</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 80%<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 300px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
			<span class="token property">justify-content</span><span class="token punctuation">:</span> space-around
		<span class="token punctuation">}</span>
		<span class="token selector">div span</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span>            
			<span class="token property">margin-right</span><span class="token punctuation">:</span> 5px<span class="token punctuation">;</span>    <span class="token comment">/*span之间有距离*/</span>
			<span class="token property">flex</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
	<span class="token comment">&lt;!-- 使用flex布局之后， 就不分行内元素和块级元素， 都是有大小的， 这里就可以用span了 --&gt;</span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br></div></div><h2 id="flex布局原理"><a href="#flex布局原理" class="header-anchor">#</a> flex布局原理</h2> <div class="custom-block tip"><p class="title">提示</p><p>flex 是 flexible Box 的缩写, 意为&quot;弹性布局&quot;, 用来为盒状模型提供最大的灵活性, 任何一个容器都可以指定为flex布局。</p></div><ul><li>不管是行内元素还是块级元素, 都可以指定为flex布局, 指定后, 都有大小了</li> <li>当我们为父盒子设为 flex 布局以后, 子元素的 float,clear和vertical-align属性将失效</li> <li>伸缩布局 = 弹性布局 = 伸缩盒布局 = 弹性盒布局 = flex布局</li></ul> <div class="custom-block warning"><p class="title">注意</p><p>采用 Flex 布局的元素, 称为 Flex 容器(flex container) , 简称&quot;容器&quot;; 它的所有子元素自动成为容器成员, 称为 Flex 项目(flex item), 简称&quot;项目&quot;</p></div><img src="/share/flex/02.png" alt="foo"> <div class="custom-block danger"><p class="title">总结flex布局原理</p><ol><li>就是通过给父盒子添加flex属性, 来控制子盒子的位置和排列方式</li> <li>要实现flex布局, 有的flex属性需要给父盒子添加, 有的属性要给子盒子添加</li></ol></div><h2 id="flex布局父项常见属性"><a href="#flex布局父项常见属性" class="header-anchor">#</a> flex布局父项常见属性</h2> <div class="custom-block tip"><p class="title">以后6个属性是对父元素设置的</p><ul><li>flex-direction: 设置主轴的方向</li> <li>justify-content: 设置主轴上的子元素排列方式</li> <li>flex-wrap: 设置子元素是否换行</li> <li>align-content: 设置侧轴上的子元素排列方式(多行)</li> <li>align-items: 设置侧轴上的子元素排列方式(单行)</li> <li>flex-flow: 复合属性, 相当于同时设置了flex-direction和flex-warp</li></ul></div><h2 id="flex-direction设置主轴的方向"><a href="#flex-direction设置主轴的方向" class="header-anchor">#</a> flex-direction设置主轴的方向</h2> <div class="custom-block danger"><p class="title">应用场景</p><p>主要设置子元素横向排列还是纵向排列</p></div><h3 id="主轴和侧轴"><a href="#主轴和侧轴" class="header-anchor">#</a> 主轴和侧轴</h3> <p>在flex不居中, 是分为主轴和侧轴两个方向, 同样的叫法有: 行和列, x轴和y轴</p> <ul><li>默认主轴方向就是x轴方向, 水平向右</li> <li>默认侧轴方向就是y方向, 水平向下</li></ul> <img src="/share/flex/03.png" alt="foo"> <h3 id="属性值"><a href="#属性值" class="header-anchor">#</a> 属性值</h3> <div class="custom-block danger"><p class="title">注意</p><p>flex-direction 属性决定主轴的方向(即项目的排列方向)</p> <p>注意:  <font style="color:blue;font-weight:bolder;">主轴和侧轴是会变化的</font>, 就是flex-direction设置谁为主轴, 剩下的就是侧轴, 而我们的子元素是跟着主轴来排列的</p></div><table><thead><tr><th style="text-align:left;">属性值</th> <th style="text-align:center;">说明</th></tr></thead> <tbody><tr><td style="text-align:left;">row</td> <td style="text-align:center;">默认值从左到右</td></tr> <tr><td style="text-align:left;">row-reverse</td> <td style="text-align:center;">从右到左</td></tr> <tr><td style="text-align:left;">column</td> <td style="text-align:center;">从上到下</td></tr> <tr><td style="text-align:left;">column-reverse</td> <td style="text-align:center;">从下到上</td></tr></tbody></table> <img src="/share/flex/04.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">div</span><span class="token punctuation">{</span>
			<span class="token comment">/*给父级添加flex属性,之后就是flex了  display: flex;*/</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 80%<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 300px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
			<span class="token comment">/*默认的主轴是x轴, 行 row; flex-direction: row, 那么Y轴就是侧轴*/</span>
			<span class="token comment">/*我们的元素时跟着主轴来排列的*/</span>
			<span class="token comment">/*简单了解, 翻转*/</span>
			<span class="token comment">/*flex-direction: row-reverse;*/</span>
			<span class="token comment">/*我们可以吧主轴设置为Y轴,那么x轴就成为了侧轴*/</span>
			<span class="token property">flex-direction</span><span class="token punctuation">:</span> column-reverse<span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token selector">div span</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span>            
			<span class="token property">margin-right</span><span class="token punctuation">:</span> 5px<span class="token punctuation">;</span>    <span class="token comment">/*span之间有距离*/</span>
			<span class="token property">margin-bottom</span><span class="token punctuation">:</span> 5px<span class="token punctuation">;</span>    <span class="token comment">/*span之间有距离*/</span>
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
	<span class="token comment">&lt;!-- 使用flex布局之后， 就不分行内元素和块级元素， 都是有大小的， 这里就可以用span了 --&gt;</span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br></div></div><h2 id="justify-content-设置主轴上的子元素排列方式"><a href="#justify-content-设置主轴上的子元素排列方式" class="header-anchor">#</a> justify-content 设置主轴上的子元素排列方式</h2> <blockquote><p>场景: 解决在主轴上子元素的排列方式, 比如居中对齐, 垂直居中, 平均对齐, 两边贴边后平分空间等</p></blockquote> <div class="custom-block danger"><p class="title">注意</p><ol><li>justify-content 属性定义了项目在主轴上的对其方式</li> <li><font style="color:red;font-weight:bolder;">使用这个属性之前, 一定要确定好主轴是哪个</font></li></ol></div><table><thead><tr><th style="text-align:left;">属性值</th> <th style="text-align:center;">说明</th></tr></thead> <tbody><tr><td style="text-align:left;">flex-start</td> <td style="text-align:center;">默认值从头部开始, 如果主轴是x轴, 则从左到右</td></tr> <tr><td style="text-align:left;">flex-end</td> <td style="text-align:center;">从尾部开始排列</td></tr> <tr><td style="text-align:left;">center</td> <td style="text-align:center;">在主轴居中对齐(如果主轴是x, 则水平居中)</td></tr> <tr><td style="text-align:left;">space-around</td> <td style="text-align:center;">平分剩余空间</td></tr> <tr><td style="text-align:left;">space-between</td> <td style="text-align:center;">先两边贴边, 再平分剩余空间(*)</td></tr></tbody></table> <p><font style="color:blue;font-weight:bolder;">主轴是X轴的情况</font></p> <img src="/share/flex/05.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">div</span><span class="token punctuation">{</span>
			<span class="token comment">/*给父级添加flex属性  display: flex;*/</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 80%<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 300px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
			<span class="token comment">/*默认的主轴是是x轴 row*/</span>
			<span class="token property">flex-direction</span><span class="token punctuation">:</span> row<span class="token punctuation">;</span>
			<span class="token comment">/*justify-content:  是设置主轴上子元素的排列方式*/</span>
			<span class="token comment">/*flex-start 从左到右排列*/</span>
			<span class="token comment">/*justify-content: flex-start;*/</span>
			<span class="token comment">/*flex-end 从尾部开始排列, 但顺序不会变哦*/</span>
			<span class="token comment">/*justify-content: flex-end;*/</span>
			<span class="token comment">/*center 让子元素居中对齐*/</span>
			<span class="token comment">/*justify-content: center;*/</span>
			<span class="token comment">/*平分剩余空间*/</span>
			<span class="token comment">/*justify-content: space-around;*/</span>
			<span class="token comment">/*先两边贴边, 再平分剩余空间*/</span>
			<span class="token property">justify-content</span><span class="token punctuation">:</span> space-between<span class="token punctuation">;</span>

		<span class="token punctuation">}</span>
		<span class="token selector">div span</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span>          
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>4<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br></div></div><p><font style="color:blue;font-weight:bolder;">主轴是Y轴的情况</font></p> <img src="/share/flex/06.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">div</span><span class="token punctuation">{</span>
			<span class="token comment">/*给父级添加flex属性  display: flex;*/</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 80%<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 300px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
			<span class="token comment">/*设置主轴为Y轴*/</span>
			<span class="token property">flex-direction</span><span class="token punctuation">:</span> column<span class="token punctuation">;</span>
			<span class="token comment">/*justify-content:  是设置主轴上子元素的排列方式*/</span>
			<span class="token comment">/*现在主轴是Y轴,设置子元素垂直居中 */</span>
			<span class="token property">justify-content</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>

		<span class="token punctuation">}</span>
		<span class="token selector">div span</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 50px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span>          
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br></div></div><h2 id="flex-wrap-设置子元素是否换行"><a href="#flex-wrap-设置子元素是否换行" class="header-anchor">#</a> flex-wrap 设置子元素是否换行</h2> <blockquote><p>场景, 父盒子装不下子盒子时, 自动换行</p></blockquote> <div class="custom-block danger"><p class="title">注意</p><ol><li><p>默认情况下, 项目都排在一条线 ( 又称&quot;轴线&quot; )上, flex-wrap属性定义, flex布局中默认是不换行的;</p></li> <li><p>假如装不下子元素:</p> <ol><li>如果在X轴上, 不会断压缩子元素宽度;</li> <li>如果在Y轴上, 会不断压缩子元素高度;</li></ol></li></ol></div><table><thead><tr><th>属性值</th> <th style="text-align:left;">说明</th></tr></thead> <tbody><tr><td>nowrap</td> <td style="text-align:left;">默认值, 不换行</td></tr> <tr><td>wrap</td> <td style="text-align:left;">换行</td></tr></tbody></table> <img src="/share/flex/07.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">div</span><span class="token punctuation">{</span>
			<span class="token comment">/*给父级添加flex属性  display: flex;*/</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">flex-direction</span><span class="token punctuation">:</span> row<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span>600px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 400px<span class="token punctuation">;</span>
		    <span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
			<span class="token comment">/*flex布局中, 默认的子元素是不换行的, 如果装不下, 
			会缩小子元素的宽度(x轴)或者高度(y轴), 放到父元素里面*/</span>
			<span class="token comment">/*flex-wrap: nowrap;*/</span>
			<span class="token comment">/*装不下子元素; 自动换行*/</span>
			<span class="token property">flex-wrap</span><span class="token punctuation">:</span> wrap<span class="token punctuation">;</span>


		<span class="token punctuation">}</span>
		<span class="token selector">div span</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span> 
			<span class="token property">color</span><span class="token punctuation">:</span> #fff<span class="token punctuation">;</span>
			<span class="token property">margin</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>         
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>4<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>5<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br></div></div><h2 id="align-items-设置侧轴上的子元素排列方式-单行"><a href="#align-items-设置侧轴上的子元素排列方式-单行" class="header-anchor">#</a> align-items 设置侧轴上的子元素排列方式(单行)</h2> <blockquote><p>场景, 解决侧轴上子元素垂直居中, 水平居中问题</p></blockquote> <div class="custom-block danger"><p class="title">注意</p><p>该属性是控制子项在侧轴 ( 默认是y轴 ) 上的排列方式, 在子项为单项 ( 单行 ) 的时候使用</p></div><table><thead><tr><th>属性值</th> <th style="text-align:left;">说明</th></tr></thead> <tbody><tr><td>flex-start</td> <td style="text-align:left;">默认值, 从上到下</td></tr> <tr><td>flex-end</td> <td style="text-align:left;">从下到上</td></tr> <tr><td>center</td> <td style="text-align:left;"><font style="color:red;font-weight:bolder;">挤在一起居中(垂直居中)</font></td></tr> <tr><td>stretch</td> <td style="text-align:left;">拉伸, 但是子盒子不要给高度, 是沿着侧轴拉满高度, 和父盒子一样高, 用得很少</td></tr></tbody></table> <p><font style="color:blue;font-weight:bolder;">主轴是X轴的情况</font></p> <img src="/share/flex/08.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">div</span><span class="token punctuation">{</span>
			<span class="token comment">/*给父级添加flex属性  display: flex;*/</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">flex-direction</span><span class="token punctuation">:</span> row<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span>600px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 400px<span class="token punctuation">;</span>
		    <span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
		    <span class="token comment">/*默认的主轴是x轴*/</span>
		    <span class="token comment">/*沿着主轴居中对齐*/</span>
		    <span class="token property">justify-content</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
		    <span class="token comment">/*沿着侧轴居中对齐*/</span>
		    <span class="token property">align-items</span><span class="token punctuation">:</span>center<span class="token punctuation">;</span>
		    <span class="token comment">/*拉伸, 但是子盒子不要给高度, 是沿着侧轴拉满高度, 和父盒子一样高, 用得很少*/</span>
		    <span class="token comment">/*align-items:stretch;*/</span>
		<span class="token punctuation">}</span>
		<span class="token selector">div span</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span> 
			<span class="token property">color</span><span class="token punctuation">:</span> #fff<span class="token punctuation">;</span>
			<span class="token property">margin</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>         
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br></div></div><p><font style="color:blue;font-weight:bolder;">主轴是Y轴的情况</font></p> <img src="/share/flex/09.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">div</span><span class="token punctuation">{</span>
			<span class="token comment">/*给父级添加flex属性  display: flex;*/</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">flex-direction</span><span class="token punctuation">:</span> row<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span>600px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 400px<span class="token punctuation">;</span>
		    <span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
		    <span class="token comment">/*默认的主轴是x轴*/</span>
		    <span class="token property">flex-direction</span><span class="token punctuation">:</span> column<span class="token punctuation">;</span>
		    <span class="token comment">/*沿着主轴居中对齐*/</span>
		    <span class="token property">justify-content</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
		    <span class="token comment">/*沿着侧轴居中对齐*/</span>
		    <span class="token property">align-items</span><span class="token punctuation">:</span>center<span class="token punctuation">;</span>
		    <span class="token comment">/*拉伸, 但是子盒子不要给高度, 是沿着侧轴拉满高度, 和父盒子一样高, 用得很少*/</span>
		    <span class="token comment">/*align-items:stretch;*/</span>
		<span class="token punctuation">}</span>
		<span class="token selector">div span</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span> 
			<span class="token property">color</span><span class="token punctuation">:</span> #fff<span class="token punctuation">;</span>
			<span class="token property">margin</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>         
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br></div></div><h2 id="align-content-设置侧轴上的子元素的排列方式-多行"><a href="#align-content-设置侧轴上的子元素的排列方式-多行" class="header-anchor">#</a> align-content 设置侧轴上的子元素的排列方式 ( 多行 )</h2> <div class="custom-block danger"><p class="title">注意</p><p>设置子项在侧轴上的排列方式, 并且只能用于子项出现 <font style="color:red;font-weight:bolder;"> 换行 </font> , 在单行下是没有效果的 。</p></div><table><thead><tr><th>属性值</th> <th style="text-align:left;">说明</th></tr></thead> <tbody><tr><td>flex-start</td> <td style="text-align:left;">默认值, 在侧轴的头部开始排列</td></tr> <tr><td>flex-end</td> <td style="text-align:left;">在侧轴的尾部开始排列</td></tr> <tr><td>center</td> <td style="text-align:left;">在侧轴中间显示</td></tr> <tr><td>stretch</td> <td style="text-align:left;">设置子项元素高度平分父元素高度</td></tr> <tr><td>space-around</td> <td style="text-align:left;">子项在侧轴平分剩余空间</td></tr> <tr><td>space-between</td> <td style="text-align:left;">子项在侧轴先分布在两头, 再平分剩余空间</td></tr></tbody></table> <img src="/share/flex/10.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">div</span><span class="token punctuation">{</span>
			<span class="token comment">/*给父级添加flex属性  display: flex;*/</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span>800px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 400px<span class="token punctuation">;</span>
		    <span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
		    <span class="token comment">/*主轴水平居中*/</span>
		    <span class="token comment">/*justify-content: space-between;*/</span>
		    <span class="token comment">/*设置换行*/</span>
		    <span class="token property">flex-wrap</span><span class="token punctuation">:</span> wrap<span class="token punctuation">;</span>
		    <span class="token comment">/*因为有了换行, 此时我们侧轴上控制子元素的对齐方式用align-content*/</span>
		    <span class="token comment">/*默认值, 在侧轴的头部开始排列flex-start*/</span>
		    <span class="token comment">/*align-content: flex-start;*/</span>
		    <span class="token comment">/*在侧轴的尾部开始排列flex-end*/</span>
		    <span class="token comment">/*align-content: flex-end;*/</span>
		    <span class="token comment">/*在侧轴中间显示*/</span>
		    <span class="token property">align-content</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
		    <span class="token comment">/*子项在侧轴先分布在两头, 再平分剩余空间*/</span>
		    <span class="token comment">/*align-content: space-between;*/</span>
		    <span class="token comment">/*子项在侧轴平分剩余空间*/</span>
		    <span class="token comment">/*align-content: space-around;*/</span>
		<span class="token punctuation">}</span>
		<span class="token selector">div span</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span> 
			<span class="token property">color</span><span class="token punctuation">:</span> #fff<span class="token punctuation">;</span>
			<span class="token property">margin</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>         
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>4<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>5<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>6<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br></div></div><h2 id="align-content和align-items-区别"><a href="#align-content和align-items-区别" class="header-anchor">#</a> align-content和align-items 区别</h2> <ul><li>align-items 适用于单行情况下, 只有上对齐, 下对齐, 居中和拉伸</li> <li>align-content 使用于换行(多行)的情况下(单行情况下无效), 可以设置上对齐, 下对齐, 居中, 拉伸以及平均分配剩余空间等属性值</li> <li>总结就是单行找align-items; 多行找align-content。</li></ul> <h2 id="flex-flow属性是flex-direction和flex-wrap属性的符合属性"><a href="#flex-flow属性是flex-direction和flex-wrap属性的符合属性" class="header-anchor">#</a> flex-flow属性是flex-direction和flex-wrap属性的符合属性</h2> <blockquote><p>flex-direction和flex-wrap属性的一种连写</p></blockquote> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>flex-flow: <span class="token function">column</span> wrap<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>等价于</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>flex-direction: <span class="token function">column</span><span class="token punctuation">;</span>
flex-wrap: wrap<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h2 id="flex布局子项常见属性"><a href="#flex布局子项常见属性" class="header-anchor">#</a> flex布局子项常见属性</h2> <ul><li>flex:  子项目占的份数</li> <li>align-self:  控制子项自己在侧轴的排列方式</li> <li>order:  定义子项的排列顺序 ( 前后顺序 )</li></ul> <h3 id="flex属性-份数"><a href="#flex属性-份数" class="header-anchor">#</a> flex属性:  份数</h3> <div class="custom-block danger"><p class="title">定义</p><ol><li><p>flex属性定义子项目分配<font style="color:red;font-weight:bolder;">剩余空间</font>, 用flex来表示占多少<font style="color:red;font-weight:bolder;">份数</font></p></li> <li><p>flex数值可以使0, 不占份数, 可以是1,2或者其他数字, 数值越大, 占用的份数就越多; 越小, 占用的份数就越少;</p></li></ol></div><div class="language-style line-numbers-mode"><pre class="language-text"><code>.item{
    flex: &lt;number&gt;; /* 默认值是0 */
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><img src="/share/flex/11.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">section</span><span class="token punctuation">{</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 60%<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
			<span class="token property">margin</span><span class="token punctuation">:</span> 0 auto<span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token comment">/*div的第一个子元素*/</span>
		<span class="token selector">section div:nth-child(1)</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token comment">/*flex: 1;*/</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span> 
		<span class="token punctuation">}</span>
		<span class="token selector">section div:nth-child(2)</span><span class="token punctuation">{</span>
			<span class="token comment">/*div1和div3固定, 剩余空间全部给中间这个div盒子*/</span>
			<span class="token property">flex</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> green<span class="token punctuation">;</span> 
		<span class="token punctuation">}</span>
		<span class="token selector">section div:nth-child(3)</span><span class="token punctuation">{</span>
			<span class="token comment">/*flex: 2;*/</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> blue<span class="token punctuation">;</span> 
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>section</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>section</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br></div></div><img src="/share/flex/12.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">p</span><span class="token punctuation">{</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 60%<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
			<span class="token property">margin</span><span class="token punctuation">:</span> 100px auto<span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token selector">p span</span><span class="token punctuation">{</span>
			<span class="token property">flex</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>	
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
		<span class="token comment">&lt;!-- p平均分配成三等份 --&gt;</span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span><span class="token value css language-css"><span class="token property">background-color</span><span class="token punctuation">:</span> blue<span class="token punctuation">;</span> </span><span class="token punctuation">&quot;</span></span></span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br></div></div><img src="/share/flex/13.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">p</span><span class="token punctuation">{</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 60%<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
			<span class="token property">margin</span><span class="token punctuation">:</span> 100px auto<span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token comment">/*盒子都平均分配剩余空间*/</span>
		<span class="token selector">p span</span><span class="token punctuation">{</span>
			<span class="token property">flex</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token comment">/*让中间盒子让2份*/</span>
		<span class="token selector">p span:nth-child(2)</span><span class="token punctuation">{</span>
			<span class="token property">flex</span><span class="token punctuation">:</span> 2<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span> 
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>	
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><h3 id="align-self-控制子项自己在侧轴上的排列方式"><a href="#align-self-控制子项自己在侧轴上的排列方式" class="header-anchor">#</a> align-self 控制子项自己在侧轴上的排列方式</h3> <blockquote><p>align-self属性允许单个项目有与其他项目不一样的对齐方式, 可覆盖 align-items 属性; 默认值为 auto ; 表示继承父元素的 align-items 属性, 如果没有父元素, 则等同于 stretch ;</p></blockquote> <img src="/share/flex/14.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">p</span><span class="token punctuation">{</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 80%<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 350px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>
			<span class="token comment">/* 让三个子盒子沿着侧轴底侧对齐 */</span>
			<span class="token comment">/*align-items: flex-end;*/</span>
			<span class="token comment">/* 我们只想让3号盒子下来底侧  */</span>
		<span class="token punctuation">}</span>
		<span class="token comment">/*盒子都平均分配剩余空间*/</span>
		
		<span class="token comment">/*让中间盒子让2份*/</span>
		<span class="token selector">p span</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span> 
			<span class="token property">margin-right</span><span class="token punctuation">:</span> 5px<span class="token punctuation">;</span> 
		<span class="token punctuation">}</span>
		<span class="token comment">/* 设置自己在侧轴上的排列方式, 只让3号盒子下来底侧  */</span>
		<span class="token selector">p span:nth-child(3)</span><span class="token punctuation">{</span>
			<span class="token property">align-self</span><span class="token punctuation">:</span> flex-end<span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>	
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br></div></div><h3 id="order-属性定义项目的排列顺序"><a href="#order-属性定义项目的排列顺序" class="header-anchor">#</a> order 属性定义项目的排列顺序</h3> <div class="custom-block danger"><p class="title">注意</p><p>数值越小, 排列越靠前, 默认为0;</p></div><img src="/share/flex/15.png" alt="foo"> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>en<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>UTF-8<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>viewport<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>width=device-width, initial-scale=1.0<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>title</span><span class="token punctuation">&gt;</span></span>Document<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>title</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/css<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
		<span class="token selector">p</span><span class="token punctuation">{</span>
			<span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 80%<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 350px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> pink<span class="token punctuation">;</span>			
		<span class="token punctuation">}</span>
		
		<span class="token selector">p span</span><span class="token punctuation">{</span>
			<span class="token property">width</span><span class="token punctuation">:</span> 150px<span class="token punctuation">;</span>
			<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
			<span class="token property">background-color</span><span class="token punctuation">:</span> purple<span class="token punctuation">;</span> 
			<span class="token property">margin-right</span><span class="token punctuation">:</span> 5px<span class="token punctuation">;</span> 
		<span class="token punctuation">}</span>
		<span class="token comment">/*把第二个盒子移到最前面*/</span>
		<span class="token selector">p span:nth-child(2)</span><span class="token punctuation">{</span>
			<span class="token comment">/* order属性默认值是0, -1比0小, 所以在1前面  */</span>
			<span class="token property">order</span><span class="token punctuation">:</span> -1<span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token selector">p span:nth-child(3)</span><span class="token punctuation">{</span>
			<span class="token property">align-self</span><span class="token punctuation">:</span> flex-end<span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>	
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>1<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br></div></div></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">2022/9/3 22:18:23</span></div></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/share/docs/flex/layout.html">
            网页布局
          </a></span></p></div> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-cb1513f6><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#flex布局体验" class="sidebar-link reco-side-flex布局体验" data-v-cb1513f6>flex布局体验</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/flex/#传统布局与flex布局" class="sidebar-link reco-side-传统布局与flex布局" data-v-cb1513f6>传统布局与flex布局</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/flex/#示例-三等分一个盒子" class="sidebar-link reco-side-示例-三等分一个盒子" data-v-cb1513f6>示例: 三等分一个盒子</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#flex布局原理" class="sidebar-link reco-side-flex布局原理" data-v-cb1513f6>flex布局原理</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#flex布局父项常见属性" class="sidebar-link reco-side-flex布局父项常见属性" data-v-cb1513f6>flex布局父项常见属性</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#flex-direction设置主轴的方向" class="sidebar-link reco-side-flex-direction设置主轴的方向" data-v-cb1513f6>flex-direction设置主轴的方向</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/flex/#主轴和侧轴" class="sidebar-link reco-side-主轴和侧轴" data-v-cb1513f6>主轴和侧轴</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/flex/#属性值" class="sidebar-link reco-side-属性值" data-v-cb1513f6>属性值</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#justify-content-设置主轴上的子元素排列方式" class="sidebar-link reco-side-justify-content-设置主轴上的子元素排列方式" data-v-cb1513f6>justify-content 设置主轴上的子元素排列方式</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#flex-wrap-设置子元素是否换行" class="sidebar-link reco-side-flex-wrap-设置子元素是否换行" data-v-cb1513f6>flex-wrap 设置子元素是否换行</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#align-items-设置侧轴上的子元素排列方式-单行" class="sidebar-link reco-side-align-items-设置侧轴上的子元素排列方式-单行" data-v-cb1513f6>align-items 设置侧轴上的子元素排列方式(单行)</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#align-content-设置侧轴上的子元素的排列方式-多行" class="sidebar-link reco-side-align-content-设置侧轴上的子元素的排列方式-多行" data-v-cb1513f6>align-content 设置侧轴上的子元素的排列方式 ( 多行 )</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#align-content和align-items-区别" class="sidebar-link reco-side-align-content和align-items-区别" data-v-cb1513f6>align-content和align-items 区别</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#flex-flow属性是flex-direction和flex-wrap属性的符合属性" class="sidebar-link reco-side-flex-flow属性是flex-direction和flex-wrap属性的符合属性" data-v-cb1513f6>flex-flow属性是flex-direction和flex-wrap属性的符合属性</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/flex/#flex布局子项常见属性" class="sidebar-link reco-side-flex布局子项常见属性" data-v-cb1513f6>flex布局子项常见属性</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/flex/#flex属性-份数" class="sidebar-link reco-side-flex属性-份数" data-v-cb1513f6>flex属性:  份数</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/flex/#align-self-控制子项自己在侧轴上的排列方式" class="sidebar-link reco-side-align-self-控制子项自己在侧轴上的排列方式" data-v-cb1513f6>align-self 控制子项自己在侧轴上的排列方式</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/flex/#order-属性定义项目的排列顺序" class="sidebar-link reco-side-order-属性定义项目的排列顺序" data-v-cb1513f6>order 属性定义项目的排列顺序</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div><!----><div class="kanbanniang" data-v-5775ee02><div class="banniang-container" style="display:;" data-v-5775ee02><div class="messageBox" style="left:68px;bottom:370px;display:none;" data-v-5775ee02>
      欢迎来到我的博客
    </div> <div class="operation" style="right:90px;bottom:40px;display:none;" data-v-5775ee02><i class="kbnfont kbn-ban-home ban-home" data-v-5775ee02></i> <i class="kbnfont kbn-ban-message message" data-v-5775ee02></i> <i class="kbnfont kbn-ban-close close" data-v-5775ee02></i> <a target="_blank" href="https://vuepress-theme-reco.recoluan.com/views/plugins/kanbanniang.html" data-v-5775ee02><i class="kbnfont kbn-ban-info info" data-v-5775ee02></i></a> <i class="kbnfont kbn-ban-theme skin" style="display:;" data-v-5775ee02></i></div> <canvas id="banniang" width="260px" height="420" class="live2d" style="right:200px;bottom:20px;opacity:0.4;" data-v-5775ee02></canvas></div> <div class="showBanNiang" style="display:none;" data-v-5775ee02>
    看板娘
  </div></div><canvas id="vuepress-canvas-cursor"></canvas><!----><div class="RibbonAnimation"></div><!----></div></div>
    <script src="/share/assets/js/app.706684de.js" defer></script><script src="/share/assets/js/3.4685d505.js" defer></script><script src="/share/assets/js/1.b12738fb.js" defer></script><script src="/share/assets/js/25.c1c35d96.js" defer></script><script src="/share/assets/js/9.4e81f08e.js" defer></script>
  </body>
</html>
